from django.db import models

from datetime import datetime
'''
@用户信息
'''

class User(models.Model):
    username = models.CharField("用户名",max_length=64)
    email = models.EmailField("邮箱")
    password = models.CharField("密码",max_length=33)
    phone = models.CharField("电话",max_length=24, null=True)
    isadmin = models.BooleanField("是否是管理员",default=False)

    def __str__(self):
        return self.username

'''
@话题信息
'''


class Topic(models.Model):
    topicname = models.CharField("话题名称", max_length=16)
    def __str__(self):
        return self.topicname


'''
@文章信息
'''


class Article(models.Model):
    title = models.CharField("标题", max_length=128)
    brief = models.CharField("简介", max_length=512)
    content = models.CharField(verbose_name='文章详情',max_length=1500)
    author = models.ForeignKey(User, verbose_name="作者",on_delete=models.CASCADE)
    topic = models.ForeignKey(Topic, on_delete=models.CASCADE, verbose_name="所属话题")
    time = models.DateTimeField("发布时间", default=datetime.now)
    image = models.ImageField("图片", default="None")
    def __str__(self):
        return self.title

'''
@评论信息
'''

class Comment(models.Model):
    article = models.ForeignKey(Article, on_delete=models.CASCADE, verbose_name="所属文章")
    comment_author = models.CharField("作者",max_length=20)
    content = models.CharField(max_length=500)
    comment_time = models.DateTimeField("发布时间", default=datetime.now)
